#include "imageresizedialog.h"
#include "ui_imageresizedialog.h"

ImageResizeDialog::ImageResizeDialog(QWidget *parent,int imageWidth,  int imageHeight) :
    QDialog(parent),
    ui(new Ui::ImageResizeDialog)
{
    ui->setupUi(this);
	ui->newHeight->setText(QString("%1").arg(imageHeight));
		ui->newWidth->setText(QString("%1").arg(imageWidth));
		originalHeight = imageHeight;
		originalWidth = imageWidth;
		connect(ui->resizeType, SIGNAL(currentIndexChanged(QString)), this, SLOT(updateComboBox(QString)));
}

QSize* ImageResizeDialog::getNewSize(){
	return new QSize(getNewWidth(), getNewHeight());

}
int ImageResizeDialog::getNewHeight()
{
	QString yup = ui->resizeType->currentText();
	return (ui->resizeType->currentText() == "Percent") ?
		originalHeight * float(.01 * ui->newHeight->text().toInt()) : ui->newHeight->text().toInt();
}

int ImageResizeDialog::getNewWidth()
{
		return (ui->resizeType->currentText() == "Percent") ?
		originalWidth * float(.01 * ui->newWidth->text().toInt()) : ui->newWidth->text().toInt();
}
ImageResizeDialog::~ImageResizeDialog()
{
    delete ui;
}

QString ImageResizeDialog::getResizeType()
{
	return "yup";
}

void ImageResizeDialog::updateComboBox(QString string)
{
	if(string == "Percent")
	{
			ui->newHeight->setText(QString("%1").arg(100));
			ui->newWidth->setText(QString("%1").arg(100));
	}
	else
	{
		ui->newHeight->setText(QString("%1").arg(originalHeight));
			ui->newWidth->setText(QString("%1").arg(originalWidth));
	}

		int resizeIndex = ui->comboBox_2->findText(string);
		 ui->comboBox_2->setCurrentIndex(resizeIndex);

}

